<!DOCTYPE html>
<html lang="zh-CN"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <!--<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />-->
    <link rel="stylesheet" data-th-href="@{/css/font.css}">
    <link rel="stylesheet" data-th-href="@{/css/xadmin.css}">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" data-th-src="@{/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" data-th-src="@{/js/xadmin.js}"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">
    <form class="layui-form" id="update_form" data-th-action="@{/activity/update}">
        <input type="hidden" name="id" data-th-value="${activity.id}">
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>活动名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name" required="" lay-verify="required" data-th-value="${activity.name}"
                       autocomplete="off" class="layui-input">
            </div>
            <!--<div class="layui-form-mid layui-word-aux">-->
            <!--<span class="x-red">*</span>-->
            <!--</div>-->
        </div>
        <div class="layui-form-item">
            <label for="enrollNum" class="layui-form-label">
                <span class="x-red">*</span>入围人数
            </label>
            <div class="layui-input-inline">
                <input type="text" id="enrollNum" name="enrollNum" required="" lay-verify="required|number" data-th-value="${activity.enrollNum}"
                       autocomplete="off" class="layui-input">
            </div>
            <!--<div class="layui-form-mid layui-word-aux">-->
            <!--<span class="x-red">*</span>-->
            <!--</div>-->
        </div>
        <div class="layui-form-item">
            <label for="insideNum" class="layui-form-label">
                <span class="x-red">*</span>场内人数
            </label>
            <div class="layui-input-inline">
                <input type="text" id="insideNum" name="insideNum" required="" lay-verify="required|number" data-th-value="${activity.insideNum}"
                       autocomplete="off" class="layui-input">
            </div>
            <!--<div class="layui-form-mid layui-word-aux">-->
            <!--<span class="x-red">*</span>-->
            <!--</div>-->
        </div>
        <!--<div class="layui-form-item">-->
        <!--<label class="layui-form-label"><span class="x-red">*</span>角色</label>-->
        <!--<div class="layui-input-block">-->
        <!--<input type="checkbox" name="like1[write]" lay-skin="primary" title="超级管理员" checked="">-->
        <!--<input type="checkbox" name="like1[read]" lay-skin="primary" title="编辑人员">-->
        <!--<input type="checkbox" name="like1[write]" lay-skin="primary" title="宣传人员" checked="">-->
        <!--</div>-->
        <!--</div>-->
        <div class="layui-form-item">
            <label for="reselectionNum" class="layui-form-label">
                <span class="x-red">*</span>未入围中奖人数
            </label>
            <div class="layui-input-inline">
                <input type="text" id="reselectionNum" name="reselectionNum" required="" lay-verify="required|number" data-th-value="${activity.reselectionNum}"
                       autocomplete="off" class="layui-input">
            </div>
            <!--<div class="layui-form-mid layui-word-aux">-->
            <!--6到16个字符-->
            <!--</div>-->
        </div>
        <div class="layui-form-item">
            <label for="amountLow" class="layui-form-label">
                <span class="x-red">*</span>发票最低金额
            </label>
            <div class="layui-input-inline">
                <input type="text" id="amountLow" name="amountLow" required="" lay-verify="required|number" data-th-value="${activity.amountLow}"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="startDate" class="layui-form-label">
                <span class="x-red">*</span>报名开始时间
            </label>
            <div class="layui-input-inline">
                <input type="text" id="startDate" name="startDate" required="" lay-verify="required" data-th-value="${startDate}"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="endDate" class="layui-form-label">
                <span class="x-red">*</span>报名截至时间
            </label>
            <div class="layui-input-inline">
                <input type="text" id="endDate" name="endDate" required="" lay-verify="required" data-th-value="${endDate}"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <button  class="layui-btn" lay-filter="update" lay-submit="update">立即提交</button>
        </div>
    </form>
</div>
<script>
    layui.use(['form','layer','laydate'], function(){
        $ = layui.jquery;
        var form = layui.form
                ,layer = layui.layer
                ,laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#startDate' //指定元素
        });
        //执行一个laydate实例
        laydate.render({
            elem: '#endDate' //指定元素
        });

        form.on("submit(update)",function(data){
            var index = layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
            var url = $("#update_form").attr("action");
            var data = $("#update_form").serializeArray(); //自动将form表单封装成json
            //console.log(url);
            setTimeout(function(){
                $.ajax({
                    type:"post",
                    url:url,
                    data:data,
                    dataType:"json",
                    success:function(result){
                        layer.close(index);
                        //console.log(result.message);

                        layer.msg(result.message);
                        //刷新父页面
//							console.log(window.location);
                        if(result.code==0){
                            setTimeout(function(){window.location.href = "/activity/getlist"},2000)
                        }
                        }

                });
                layer.close(index);
            },1000);
            return false;
        })


        //自定义验证规则
        form.verify({
            nikename: function(value){
                if(value.length < 5){
                    return '昵称至少得5个字符啊';
                }
            }
            ,pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,repass: function(value){
                if($('#L_pass').val()!=$('#L_repass').val()){
                    return '两次密码不一致';
                }
            }
        });
    });
</script>
</body>
</html>